/*
 * Copyright (c) 2018 by TangChenBeiJian Information Technology Co.Ltd.
 *           All rights reserved
 */

package org.cx.util;




import org.cx.constant.BaseCode;
import org.cx.constant.ServerCodeType;
import org.cx.exception.BaseException;




public final class AssertUtil {





    /**
     * obj等于null时，抛错
     *
     * @param obj
     * @param tips
     */
    public static void isNotNull(Object obj, String tips) {
        isNotNull(obj, tips, ServerCodeType.USER_NOT_FOUND.getCode());
    }

    /**
     * obj等于null时，抛错
     *
     * @param obj
     * @param bc
     */
    public static void isNotNull(Object obj, BaseCode bc) {
        isNotNull(obj, bc.errorMsg(), bc.status());
    }

    /**
     * obj等于null时，抛错
     *
     * @param obj
     * @param tips
     * @param errCode 默认抛参数异常
     */
    public static void isNotNull(Object obj, String tips, int errCode) {
        if (obj == null) {
            throw new BaseException(errCode, tips);
        }
    }




    /**
     * bool不等于true时，抛错
     * @param bool
     * @param tips
     */
    public static void isTrue(boolean bool, String tips) {
        isTrue(bool, tips, ServerCodeType.PARAM_ERROR.getCode());
    }

    /**
     * bool不等于true时，抛错
     *
     * @param bool
     * @param bc
     */
    public static void isTrue(boolean bool, BaseCode bc) {
        isTrue(bool, bc.errorMsg(), bc.status());
    }


    /**
     * bool不等于true时，抛错
     *
     * @param bool
     * @param tips
     * @param errCode 默认抛参数异常
     */
    public static void isTrue(boolean bool, String tips, int errCode) {
        if (!bool) {
            throw new BaseException(errCode, tips);
        }
    }



}
